home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / Locus / Source / Activator.m < prev    next >
Text File  |  1995-06-12  |  6KB  |  306 lines

  1.  
  2. /*
  3.     Copyright 1993  Jeremy Slade.
  4.  
  5.     You are free to use all or any parts of the Locus project
  6.     however you wish, just give credit where credit is due.
  7.     The author (Jeremy Slade) shall not be held responsible
  8.     for any damages that result out of use or misuse of any
  9.     part of this project.
  10.  
  11. */
  12.  
  13. /*
  14.     Project: Locus
  15.  
  16.     File: Activator.h
  17.  
  18.     Description: See Activator.h
  19.     
  20.     Original Author: Jeremy Slade
  21.  
  22.     Revision History:
  23.         Created
  24.             V.101    JGS    Tue Mar  9 18:44:28 GMT-0700 1993
  25.  
  26. */
  27.  
  28.  
  29. #import "Activator.h"
  30.  
  31. #import "ActivatorBar.h"
  32. #import "Globals.h"
  33.  
  34.  
  35. @implementation Activator : Object
  36.  
  37.  
  38. // -------------------------------------------------------------------------
  39. //   Creating, Initializing
  40. // -------------------------------------------------------------------------
  41.  
  42.  
  43. + initialize
  44. {
  45.     [self setVersion:Activator_VERSION];
  46.     return ( self );
  47. }
  48.  
  49.  
  50.  
  51. - init
  52. {
  53.     [super init];
  54.     
  55.     // Set default colors
  56.     fillColor = NX_COLORWHITE;
  57.     borderColor = NX_COLORBLACK;
  58.     
  59.     // Create the bars...
  60.     topBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_TOP];
  61.     bottomBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_BOTTOM];
  62.     leftBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_LEFT];
  63.     rightBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_RIGHT];
  64.     [topBar setDelegate:self];
  65.     [leftBar setDelegate:self];
  66.     [rightBar setDelegate:self];
  67.     [bottomBar setDelegate:self];
  68.     
  69.     [self setBar:ACT_NONE on:NO];
  70.     return ( self );
  71. }
  72.  
  73.  
  74.  
  75. - free
  76. {
  77.     [self hide:self];
  78.     [topBar free];
  79.     [bottomBar free];
  80.     [leftBar free];
  81.     [rightBar free];
  82.     return ( [super free] );
  83. }
  84.     
  85.  
  86.  
  87. // -------------------------------------------------------------------------
  88. //   Setting the Delegate
  89. // -------------------------------------------------------------------------
  90.  
  91.  
  92. - setDelegate:anObj
  93. {
  94.     delegate = anObj;
  95.     return ( self );
  96. }
  97.  
  98.  
  99.  
  100. - delegate
  101. {
  102.     return ( self );
  103. }
  104.  
  105.  
  106.  
  107. // -------------------------------------------------------------------------
  108. //   Controlling the Bars
  109. // -------------------------------------------------------------------------
  110.  
  111.  
  112. - setBar:(int)mask on:(BOOL)flag
  113. /*
  114.     Turn on the bar(s) corresponding to mask.  If mask is ACT_NONE, turn off all bars.
  115. */
  116. {
  117.     int newMask = barMask;
  118.     
  119.     if ( mask == ACT_NONE ) { // hide all bars
  120.         newMask = ACT_NONE;
  121.     } else {
  122.         if ( mask & ACT_TOP ) {
  123.             if ( flag ) newMask |= ACT_TOP;
  124.                 else newMask &= ~ACT_TOP;
  125.         }
  126.         if ( mask & ACT_LEFT ) {
  127.             if ( flag ) newMask |= ACT_LEFT;
  128.                 else newMask &= ~ACT_LEFT;
  129.         }
  130.         if ( mask & ACT_RIGHT ) {
  131.             if ( flag ) newMask |= ACT_RIGHT;
  132.                 else newMask &= ~ACT_RIGHT;
  133.         }
  134.         if ( mask & ACT_BOTTOM ) {
  135.             if ( flag ) newMask |= ACT_BOTTOM;
  136.                 else newMask &= ~ACT_BOTTOM;
  137.         }
  138.     }
  139.     
  140.     // Set the bar positions according to mask
  141.     barMask = newMask;
  142.     [topBar setPosition:((barMask & ACT_TOP) ? ABAR_TOP : ABAR_NONE)];
  143.     [leftBar setPosition:((barMask & ACT_LEFT) ? ABAR_LEFT : ABAR_NONE)];
  144.     [rightBar setPosition:((barMask & ACT_RIGHT) ? ABAR_RIGHT : ABAR_NONE)];
  145.     [bottomBar setPosition:
  146.         ((barMask & ACT_BOTTOM) ? ABAR_BOTTOM : ABAR_NONE)];
  147.     
  148.     [self show:self];
  149.     return ( self );
  150. }
  151.  
  152.  
  153.  
  154. - (int)barMask
  155. {
  156.     return ( barMask );
  157. }
  158.  
  159.  
  160.  
  161. - (BOOL)isBarOn:(int)mask
  162. /*
  163.     This method returns YES if the bar(s) corresponding to mask is turned on (visible), or NO if it is not.
  164. */
  165. {
  166.     return ( (barMask & mask) ? YES : NO );
  167. }
  168.  
  169.  
  170.  
  171. - show:sender
  172. /*
  173.     Show all the bars.  Since each individual bar knows if it is supposed to be on screen or now, telling it to show itself will do the right thing regardless.
  174. */
  175. {
  176.     [topBar show:sender];
  177.     [leftBar show:sender];
  178.     [rightBar show:sender];
  179.     [bottomBar show:sender];
  180.     return ( self );
  181. }
  182.  
  183.  
  184.  
  185. - hide:sender
  186. /*
  187.     Hide all of the activator bars.
  188. */
  189. {
  190.     [topBar hide:sender];
  191.     [leftBar hide:sender];
  192.     [rightBar hide:sender];
  193.     [bottomBar hide:sender];
  194.     return ( self );
  195. }
  196.  
  197.  
  198.  
  199. - setColor:(NXColor)color
  200. /*
  201.     Set the fill color of all the activator bars.
  202. */
  203. {
  204.     fillColor = color;
  205.     [topBar setColor:color];
  206.     [leftBar setColor:color];
  207.     [rightBar setColor:color];
  208.     [bottomBar setColor:color];
  209.     return ( self );
  210. }
  211.  
  212.  
  213.  
  214. -(NXColor)color
  215. {
  216.     return ( fillColor );
  217. }
  218.  
  219.  
  220.  
  221. - setBorderColor:(NXColor)color
  222. /*
  223.     Set the border color of all the activator bars.
  224. */
  225. {
  226.     borderColor = color;
  227.     [topBar setBorderColor:color];
  228.     [leftBar setBorderColor:color];
  229.     [rightBar setBorderColor:color];
  230.     [bottomBar setBorderColor:color];
  231.     return ( self );
  232. }
  233.  
  234.  
  235.  
  236. -(NXColor)borderColor
  237. {
  238.     return ( borderColor );
  239. }
  240.  
  241.  
  242.  
  243. - setFloating:(BOOL)flag
  244. /*
  245.     Sets the floatActivator global to flag.  The Activator Bars check this flag to determine which window tier to display in.  Calling setBar:on: indirectly results in having a setPosition: message sent to each of the bars, causing them to place themselves in the proper tier.
  246. */
  247. {
  248.     floatActivator = flag;
  249.     [self setBar:barMask on:YES];
  250.     return ( self );
  251. }
  252.  
  253.  
  254.  
  255. - (BOOL)isFloating
  256. {
  257.     return ( floatActivator );
  258. }
  259.  
  260.  
  261.  
  262. // -------------------------------------------------------------------------
  263. //   Activation
  264. // -------------------------------------------------------------------------
  265.  
  266.  
  267. - barHit:sender
  268. /*
  269.     This method is called by one of the Activator Bars when it is clicked in.  We simply inform our delegate that we were hit.
  270. */
  271. {
  272.     if ( [delegate respondsTo:@selector(activatorHit:)] )
  273.         [delegate activatorHit:self];
  274.     return ( self );
  275. }
  276.  
  277.  
  278.  
  279. // -------------------------------------------------------------------------
  280. //   Enabling Dragging
  281. // -------------------------------------------------------------------------
  282.  
  283.  
  284. - setDraggingEnabled:(BOOL)flag
  285. /*
  286.     When dragging into the Activator is enabled, the Activator bars can each act as dragging destinations for the NXDraggingProtocol for the types defined by dragInTypes -- currently only handles NXFilenamePboardTypes.  When dragging is disabled, the bars are unregistered so they won't respond as dragging destinations.
  287. */
  288. {
  289.     if ( flag == YES ) {
  290.         [leftBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
  291.         [topBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
  292.         [rightBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
  293.         [bottomBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
  294.     } else {
  295.         [leftBar unregisterDraggedTypes];
  296.         [topBar unregisterDraggedTypes];
  297.         [rightBar unregisterDraggedTypes];
  298.         [bottomBar unregisterDraggedTypes];
  299.     }
  300.     return ( self );
  301. }
  302.  
  303.  
  304.  
  305. @end
  306.